<div><h1>Contact messages</h1></div>
<div class="container">{$search}</div>
<div class="alert-success" style="text-align: center">
    <table class="table table-bordered table-striped table-hover" >
        <thead>
        <tr>
            <th></th>
            <th>N</th>
            <th><a id="submitted" class="sort">Submitted</a></th>
            <th><a id="firstName" class="sort">First Name</a></th>
            <th><a id="lastName" class="sort">Last Name</a></th>
            <th><a id="phone" class="sort">Phone</a></th>
            <th>Delete</th>
        </tr>
        </thead>
        <tbody>
        {$i = 1}
        {foreach $messages as $message}
            <tr>
                <td width="10">
                    <label>
                    <input type="checkbox" class="deleteBox" id="{$message['id']}">
                    </label>
                </td>
                <td data-id="{$message['id']}" class="messageRow">{$i++}</td>
                <td data-id="{$message['id']}" class="messageRow">{$message['submitted']}</td>
                <td data-id="{$message['id']}" class="messageRow">{$message['firstName']}</td>
                <td data-id="{$message['id']}" class="messageRow">{$message['lastName']}</td>
                <td data-id="{$message['id']}" class="messageRow">{$message['phone']}</td>
                <td>
                    <a class="btn btn-info" href="{$baseUri}/admin/contact/show/{$message['id']}">View</a>
                    <a class="btn btn-info" href="{$baseUri}/admin/contact/delete/{$message['id']}" onclick="return confirm('Are you sure you want to delete the message')">Delete</a>
                </td>
            </tr>
        {/foreach}
            <tr>
                <td colspan="3" align="left">
                    <div>
                        <a class="btn btn-info" id="checkAll">Check All</a>
                        <a class="btn btn-info" id="unCheckAll">UnCheck All</a>
                        <form style="display: inline" method="post" id="sendId" action="{$baseUri}/admin/contact/delete">
                            <input type="hidden" id="checkboxId" name="checkboxId">
                            <input class="btn btn-info" type="button" id="delete" value="Delete Selected">
                        </form>
                    </div>
                </td>

            </tr>
        </tbody>
    </table>

</div>

<script type='text/javascript' src="{$baseUri}/js/module/contact/controller.js"></script>
<script type='text/javascript'>
    var message = new module.contact.MessageView({
        checkAllId:     'checkAll',
        deleteBox:      'deleteBox',
        unCheckAllId:   'unCheckAll',
        deleteId:       'delete',
        checkboxId:     'checkboxId',
        sendId:         'sendId'
    });

    $(document).ready(function() {
        message.setCheckAll();
        message.setUnCheckAll();
        message.setDelete();
        $('.messageRow').click(function(event) {
            window.location.href = '{$baseUri}/admin/contact/show/' + $(this).data('id');
        });
        $('.sort').click(function(event) {
            window.location.href = '{$baseUri}/admin/contact?{$query}&order=' + this.id + '{$desc}';
        });
    });
</script>
